package recordsDatabase;




import java.util.ArrayList;

public class ListOfCategoryDetails{
	// create the list
	private ArrayList<CategoryDetails> categoryDetailsList;
	private static volatile ListOfCategoryDetails instance;

	// This method is called getInstance. It uses a double - locking mechanism
	// to ensure
	// synchronization between threads when accessed so that no more than one
	// instance is created.
	// Finally the instance of the single List of records is returned.

	public static ListOfCategoryDetails getInstance() {
		if (instance == null) {
			synchronized (ListOfCategoryDetails.class) {
				if (instance == null)
					instance = new ListOfCategoryDetails();
			}
		}
		return instance;
	}
	
	private ListOfCategoryDetails(){
		categoryDetailsList = new ArrayList<CategoryDetails>();
	}

	public ArrayList<CategoryDetails> getCategoryDetailsList(){
		return categoryDetailsList;
	}
	
	public void addEntry(CategoryDetails cd){
		categoryDetailsList.add(cd);
		categoryDetailsList.trimToSize();
	}
	
	public CategoryDetails getCategoryDetails(String entry){
		CategoryDetails tmpCategoryDetails = null;
			for (CategoryDetails cd: categoryDetailsList){
				if (cd.getField().equals(entry)){
					return cd;
				}
			} 
		return tmpCategoryDetails;
	}
	
	public void reset(){
		categoryDetailsList.clear();
	}
	
	
}
